﻿//
// VKSL - Visual Knowledge in Second Life
// 2007(c) CC License by-nc-sa-2.5-it
//
// Authors:
//     JonnyBee Cioc    jonny@vulca.no
//     VisionRaymaker   vision.raymaker@vulca.no

// ===[ LICENSE ]=======================================

// License Creative Commons Attribution-Noncommercial-Share Alike 2.5 Italy
// http://creativecommons.org/licenses/by-nc-sa/2.5/it/

// ===[ CHANGE LOG ]====================================
integer version_major    =  1;
integer version_minor    =  0;
integer version_revision = 13;

// 2007-12-07 v1.0.13: first revision error dialog module

// ===[ CONSTANTS ]=====================================
integer LINK_NUMBER                    = LINK_SET;

// LINKED MESSAGE PUBLIC INTERFACE
// menu linked message commands
integer MESSAGELINKED_RESET            = 0xFFFF;
integer MESSAGELINKED_MODULEREADY      = 0xFFFE;

integer MESSAGELINKED_ERRORMASK        = 0x4000;
integer MESSAGELINKED_LISTOVERFLOW     = 0x4001;
integer MESSAGELINKED_ILLEGALPARAM     = 0x4002;
integer MESSAGELINKED_TRUNCATEDMESSAGE = 0x4003;

list    ERROR_MESSAGES;
key     link_key;


// ===[ UTILITY FUNCTIONS ]=======================================

sendML(integer messagelinked, string message)
{
    llMessageLinked(LINK_NUMBER, messagelinked, message, link_key);
}


string version() { return " v"+(string)version_major+"."+(string)version_minor+"."+(string)version_revision; }




// ===[ STATE ]===================================================

default
{
    state_entry()
    {
        link_key = llGetLinkKey(llGetLinkNumber());

        ERROR_MESSAGES= [
            MESSAGELINKED_LISTOVERFLOW,     "I can't allocate more than 64 channel.",
            MESSAGELINKED_ILLEGALPARAM,     "Internal Error. Wrong menu id.",
            MESSAGELINKED_TRUNCATEDMESSAGE, "Message truncated. Maybe loss of information"
        ];

        sendML(MESSAGELINKED_MODULEREADY, llGetScriptName()+" "+version());
       
    }

    link_message(integer sender_number, integer number, string message, key avatar)
    {
        if((number & MESSAGELINKED_ERRORMASK) == MESSAGELINKED_ERRORMASK) {
            integer index = llListFindList(llList2ListStrided(ERROR_MESSAGES,0,-1,2), [message]);
            if(~index)
                llDialog(avatar, llList2String(ERROR_MESSAGES, (index<<1)+1), [], -1);
        }
        else if(number==MESSAGELINKED_RESET)
            llResetScript();
    }
}